package com.lmind.core.message;

import com.lmind.core.async.ResultHandler;
import com.lmind.core.gps.terminal.message.AccessMessage;
import com.lmind.core.gps.terminal.message.ReplyMessage;

public class MyMessagePipe extends PipelineManager implements RequestResponseProcessor {

	public MyMessagePipe() {
		setMessageProcessor(this);
	}

	@Override
	public boolean isRequest(MessagePipe connection, Object message) {
		if (message instanceof AccessMessage) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isResponse(MessagePipe connection, Object message) {
		return message instanceof ReplyMessage;
	}

	@Override
	public void process(MessagePipe connection, Object message,
			ResultHandler<Object> handler) {
		if (message instanceof AccessMessage) {
			AccessMessage access = (AccessMessage)message;
			handler.result(new ReplyMessage(true, access.getDeviceSerial()));
		}
	}

}
